package models

import "gorm.io/gorm"

type Book struct {
	gorm.Model
	Title      string
	Author     string
	Image      string
	Type       string
	AddressUrl string
}

func (b *Book) CreateBook() error {
	return DB.Create(&b).Error
}
func (b *Book) GetBooksList(title string) (BookList []Book, err error) {
	Clt := DB.Model(&Book{})
	if title != "" {
		Clt = Clt.Where("title like ?", "%"+title+"%")
	}
	err = Clt.Find(&BookList).Error
	return BookList, err
}
func (b *Book) DelBook() error {
	return DB.Delete(&b).Error
}
